{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 元卫南 赏金分析\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pymongo\n",
    "client = pymongo.MongoClient('10.18.6.46',27001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "doc=client['xueqiu']['reward']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "result =[]\n",
    "for i in doc.find({},{'_id':0}):\n",
    "    result.append(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "8968"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>been_reward</th>\n",
       "      <th>created_at</th>\n",
       "      <th>description</th>\n",
       "      <th>name</th>\n",
       "      <th>origin_post_id</th>\n",
       "      <th>user_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>6.00</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>2019-08-13 21:31:36</td>\n",
       "      <td>None</td>\n",
       "      <td>慕狼为友</td>\n",
       "      <td>131085314</td>\n",
       "      <td>1880162437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.00</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>2019-08-13 22:03:16</td>\n",
       "      <td>价值兜底，趋势赚钱，分批买卖，组合选股。</td>\n",
       "      <td>秦韬</td>\n",
       "      <td>131085314</td>\n",
       "      <td>9644764163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.00</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>2019-08-13 21:51:36</td>\n",
       "      <td>比较懒，有钱就定期买入一些，现在主要买入一些指数基金</td>\n",
       "      <td>Betula11</td>\n",
       "      <td>131085314</td>\n",
       "      <td>3256958535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>66.66</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>2019-08-13 08:09:38</td>\n",
       "      <td></td>\n",
       "      <td>Shero冉冉7</td>\n",
       "      <td>131039085</td>\n",
       "      <td>4102521305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>19.99</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>2019-08-13 15:11:39</td>\n",
       "      <td>失去的会以另外的方式永远存在</td>\n",
       "      <td>babyluo</td>\n",
       "      <td>131039085</td>\n",
       "      <td>8941786191</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   amount been_reward           created_at                 description  \\\n",
       "0    6.00         元卫南  2019-08-13 21:31:36                        None   \n",
       "1    1.00         元卫南  2019-08-13 22:03:16        价值兜底，趋势赚钱，分批买卖，组合选股。   \n",
       "2    1.00         元卫南  2019-08-13 21:51:36  比较懒，有钱就定期买入一些，现在主要买入一些指数基金   \n",
       "3   66.66         元卫南  2019-08-13 08:09:38                               \n",
       "4   19.99         元卫南  2019-08-13 15:11:39              失去的会以另外的方式永远存在   \n",
       "\n",
       "       name  origin_post_id     user_id  \n",
       "0      慕狼为友       131085314  1880162437  \n",
       "1        秦韬       131085314  9644764163  \n",
       "2  Betula11       131085314  3256958535  \n",
       "3  Shero冉冉7       131039085  4102521305  \n",
       "4   babyluo       131039085  8941786191  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 8968 entries, 0 to 8967\n",
      "Data columns (total 7 columns):\n",
      "amount            8968 non-null float64\n",
      "been_reward       8968 non-null object\n",
      "created_at        8968 non-null object\n",
      "description       6536 non-null object\n",
      "name              8968 non-null object\n",
      "origin_post_id    8968 non-null int64\n",
      "user_id           8968 non-null int64\n",
      "dtypes: float64(1), int64(2), object(4)\n",
      "memory usage: 490.5+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['created_at']=pd.to_datetime(df['created_at'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 8968 entries, 0 to 8967\n",
      "Data columns (total 7 columns):\n",
      "amount            8968 non-null float64\n",
      "been_reward       8968 non-null object\n",
      "created_at        8968 non-null datetime64[ns]\n",
      "description       6536 non-null object\n",
      "name              8968 non-null object\n",
      "origin_post_id    8968 non-null int64\n",
      "user_id           8968 non-null int64\n",
      "dtypes: datetime64[ns](1), float64(1), int64(2), object(3)\n",
      "memory usage: 490.5+ KB\n"
     ]
    }
   ],
   "source": [
    "df.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df.set_index('created_at',drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "      <th>been_reward</th>\n",
       "      <th>description</th>\n",
       "      <th>name</th>\n",
       "      <th>origin_post_id</th>\n",
       "      <th>user_id</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>created_at</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-13 21:31:36</th>\n",
       "      <td>6.00</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>None</td>\n",
       "      <td>慕狼为友</td>\n",
       "      <td>131085314</td>\n",
       "      <td>1880162437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-13 22:03:16</th>\n",
       "      <td>1.00</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>价值兜底，趋势赚钱，分批买卖，组合选股。</td>\n",
       "      <td>秦韬</td>\n",
       "      <td>131085314</td>\n",
       "      <td>9644764163</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-13 21:51:36</th>\n",
       "      <td>1.00</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>比较懒，有钱就定期买入一些，现在主要买入一些指数基金</td>\n",
       "      <td>Betula11</td>\n",
       "      <td>131085314</td>\n",
       "      <td>3256958535</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-13 08:09:38</th>\n",
       "      <td>66.66</td>\n",
       "      <td>元卫南</td>\n",
       "      <td></td>\n",
       "      <td>Shero冉冉7</td>\n",
       "      <td>131039085</td>\n",
       "      <td>4102521305</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-13 15:11:39</th>\n",
       "      <td>19.99</td>\n",
       "      <td>元卫南</td>\n",
       "      <td>失去的会以另外的方式永远存在</td>\n",
       "      <td>babyluo</td>\n",
       "      <td>131039085</td>\n",
       "      <td>8941786191</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     amount been_reward                 description      name  \\\n",
       "created_at                                                                      \n",
       "2019-08-13 21:31:36    6.00         元卫南                        None      慕狼为友   \n",
       "2019-08-13 22:03:16    1.00         元卫南        价值兜底，趋势赚钱，分批买卖，组合选股。        秦韬   \n",
       "2019-08-13 21:51:36    1.00         元卫南  比较懒，有钱就定期买入一些，现在主要买入一些指数基金  Betula11   \n",
       "2019-08-13 08:09:38   66.66         元卫南                              Shero冉冉7   \n",
       "2019-08-13 15:11:39   19.99         元卫南              失去的会以另外的方式永远存在   babyluo   \n",
       "\n",
       "                     origin_post_id     user_id  \n",
       "created_at                                       \n",
       "2019-08-13 21:31:36       131085314  1880162437  \n",
       "2019-08-13 22:03:16       131085314  9644764163  \n",
       "2019-08-13 21:51:36       131085314  3256958535  \n",
       "2019-08-13 08:09:38       131039085  4102521305  \n",
       "2019-08-13 15:11:39       131039085  8941786191  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "31851.6"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['2019']['amount'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['2018']['amount'].sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
